/*
 * serial.h
 *
 *  Created on: Aug 19, 2012
 *      Author: drew
 */

#ifndef SERIAL_H_
#define SERIAL_H_

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <pthread.h>

typedef void (*vpSerialRxCallback)(char * cRxBuff);

typedef enum
{
  SERIAL_BAUDRATE_9600,
  SERIAL_BAUDRATE_19200,
  SERIAL_BAUDRATE_38400,
  SERIAL_BAUDRATE_115200
} eSerialBaudRate;

typedef enum
{
  SERIAL_PORT_1 = 1,
  SERIAL_PORT_2,
  SERIAL_PORT_3,
  SERIAL_PORT_4,
  SERIAL_PORT_5
} eSerialPort;

typedef struct
{
  int                iSerialRefNum;
  struct termios     xSettings;
  speed_t            xBaudRate;
  eSerialPort        ePort;
  vpSerialRxCallback vpRxCallback;
  pthread_t          xThreadHandle;
} xSerialDescription, * xpSerialDescription, * SerialObject;

xpSerialDescription xpSerialCreateObject( eSerialPort ePort, eSerialBaudRate eBaudRate, vpSerialRxCallback vpRxCallback );
void vSerialDestroyObject( xpSerialDescription xpSerialPort );
int iSerialInitialize( xpSerialDescription xpSerialPort );
void iSerialCleanup( xpSerialDescription xpSerialPort );
int iSerialPrint( xpSerialDescription xpSerialPort, char * cpBuff, int iLength );
int iSerialStartListenerRunLoop( xpSerialDescription xpSerialPort );

#endif /* SERIAL_H_ */
